# 1. who are late donors? (appendix table a16)

demv1<- read.csv("late_donor_fx.csv")

#vs2==0 is a late donor, vs2==1 is an on-time donors 

a<- t.test(demv1$iswhiteperson[demv1$vs2==1], 
           demv1$iswhiteperson[demv1$vs2==0])

b<- t.test(demv1$income_perc[demv1$vs2==1], 
           demv1$income_perc[demv1$vs2==0])

c<- t.test(demv1$dem[demv1$vs2==1], 
           demv1$dem[demv1$vs2==0])

d<- t.test(demv1$age[demv1$vs2==1], 
           demv1$age[demv1$vs2==0])

res_out<- data.frame(c("% white","income decile","Democrat","Age"))
names(res_out)<-"grouping"
res_out$successful<-NA
res_out$unsuccessful<-NA
res_out$ci_low<-NA
res_out$ci_high<-NA

ttests<- list(a,b,c,d)
for (i in 1:4) {
  curr_df<- ttests[[i]]
  res_out$successful[i]<- curr_df$estimate[1]
  res_out$unsuccessful[i]<- curr_df$estimate[2]
  res_out$ci_low[i]<- curr_df$conf.int[1]
  res_out$ci_high[i]<- curr_df$conf.int[2]
}


print(xtable(res_out), include.rownames=FALSE)


#########################

#2 what if late donors counted? (tab a17)
ldr<- read.csv("late_donor_reg.csv")

qqq<- felm(part~iswhiteperson*voucher_yr + income_perc*voucher_yr+sums*voucher_yr+republican*voucher_yr|as.factor(id)+as.factor(elec_year)|0|0 , data=ldr)
qqq1<- felm(part~iswhiteperson*voucher_yr|as.factor(id)+as.factor(elec_year)|0|0 , data=ldr)
qqq2<- felm(part~  income_perc*voucher_yr+as.factor(elec_year)|as.factor(id)|0|0 , data=ldr)
qqq3<- felm(part~sums*voucher_yr|as.factor(id)+as.factor(elec_year)|0|0 , data=ldr)
qqq4<- felm(part~republican*voucher_yr|as.factor(id)+as.factor(elec_year)|0|0 , data=ldr)
stargazer(qqq1, qqq2,qqq3,qqq,qqq4, df=F, no.space = T,single.row = F, title = "title", dep.var.labels = c("Likelihood of donating"), digits = 2,omit.table.layout = "n",star.cutoffs = NA)
summary(qqq, robust=T)
summary(qqq1, robust=T)
summary(qqq2, robust=T)
summary(qqq3, robust=T)
summary(qqq4, robust=T)



#######################
# 3 main results but excluding cash donors after cands hit voucher limits (table appendix a15)


excl_lim<- read.csv("rem_after_lim.csv")

qqq<- felm(part2~iswhiteperson*voucher_yr + income_perc*voucher_yr+sums*voucher_yr+republican*voucher_yr|as.factor(id)+as.factor(elec_year)|0|0 , data=excl_lim)
qqq1<- felm(part2~iswhiteperson*voucher_yr|as.factor(id)+as.factor(elec_year)|0|0 , data=excl_lim)
qqq2<- felm(part2~  income_perc*voucher_yr+as.factor(elec_year)|as.factor(id)|0|0 , data=excl_lim)
qqq3<- felm(part2~sums*voucher_yr|as.factor(id)+as.factor(elec_year)|0|0 , data=excl_lim)
qqq4<- felm(part2~republican*voucher_yr|as.factor(id)+as.factor(elec_year)|0|0 , data=excl_lim)
stargazer(qqq1, qqq2,qqq3,qqq4,qqq,df=F, no.space = T,single.row = F, title = "Controlling for different attributes, individuals in overrepresented groups are still benefitting the most from the Democracy Voucher program. elec_year fixed and Individual effects.", dep.var.labels = c("Likelihood of donating"), digits = 2,omit.table.layout = "n",star.cutoffs = NA)
summary(qqq, robust=T)
summary(qqq1, robust=T)
summary(qqq2, robust=T)
summary(qqq3, robust=T)
summary(qqq4, robust=T)


